package org.example.stack;

import java.util.List;

public class LinkedStack {

    private Node bottom = new Node(0);

    public Node getBottom() {
        return bottom;
    }

    public Node addNode(int no){
        return new Node(no);
    }

    public boolean isEmpty(){
        return bottom.next == null;
    }

    public void push(Node node){

        Node temp = bottom;
        while(temp.next != null){
            temp = temp.next;
        }
        temp.next = node;
    }

    public int pop(){
        if (isEmpty()){
            System.out.println("栈空");
            return 0;
        }
        Node temp = bottom;
        while(temp.next.next != null){
            temp = temp.next;
        }
        int no = temp.next.no;
        temp.next = null;
        return no;
    }


    public void show(Node node){
        if (isEmpty()){
            System.out.println("栈空");
            return ;
        }
        if (node == null){
            return;
        }
        show(node.next);
        if (node != bottom){
            System.out.println(node);
        }
    }

}

class Node{

    public int no;
    public Node next;

    public Node() {
    }

    public Node(int no) {
        this.no = no;
    }

    @Override
    public String toString() {
        return "Node{" +
                "no=" + no +
                '}';
    }
}